import { loginAPI } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
// import { resetRouter } from '@/router'

export default {
  namespaced: true,
  state: {
    token: getToken()
  },
  mutations: {
    // 存token
    SET_TOKEN(state, token) {
      state.token = token
      setToken(token)
    },
    // 移除token
    DEL_TOKEN(state) {
      state.token = null
      removeToken()
    }
  },
  actions: {
    // 请求登录
    async login({ commit }, data) {
      try {
        const res = await loginAPI(data)
        commit('SET_TOKEN', res.data.token)
        console.log(res)
        return res
      } catch (error) {
        console.log(error)
      }
    }

  }
}

